home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4364 / 4364.xpi / chrome / elemhidehelper.jar / content / overlayBasic.js < prev    next >
Text File  |  2009-07-01  |  3KB  |  95 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Adblock Plus Element Hiding Helper.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Wladimir Palant.
  18.  * Portions created by the Initial Developer are Copyright (C) 2006-2009
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * ***** END LICENSE BLOCK ***** */
  24.  
  25. window.addEventListener("load", ehhInit, false);
  26.  
  27. function ehhInit() {
  28.     var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  29.                                                             .getService(Components.interfaces.nsIPrefService);
  30.     var branch = prefService.getBranch("extensions.adblockplus.");
  31.  
  32.     // Check whether ABP is installed and has at least the required version
  33.     var requiredVersion = "0.7.5";
  34.     var installedVersion = "0";
  35.     try {
  36.         var abp = Components.classes["@mozilla.org/adblockplus;1"]
  37.                                                 .createInstance().wrappedJSObject;
  38.         installedVersion = abp.getInstalledVersion();
  39.     } catch(e) {}
  40.  
  41.     var parts1 = requiredVersion.split(".");
  42.     var parts2 = installedVersion.split(".");
  43.     var mustUpdate = false;
  44.     for (var i = 0; i < parts1.length; i++) {
  45.         if (parts2.length <= i || parseInt(parts1[i]) > parseInt(parts2[i])) {
  46.             mustUpdate = true;
  47.             break;
  48.         }
  49.         if (parseInt(parts1[i]) < parseInt(parts2[i]))
  50.             break;
  51.     }
  52.  
  53.     // Show warning about required ABP update if necessary
  54.     if (mustUpdate) {
  55.         var noWarning = {value: false};
  56.         try {
  57.             noWarning.value = branch.getBoolPref("ehh.norequirementswarning");
  58.         } catch(e) {}
  59.  
  60.         if (!noWarning.value) {
  61.             // Make sure we don't show the warning twice
  62.             var hiddenWnd = Components.classes["@mozilla.org/appshell/appShellService;1"]
  63.                                                                 .getService(Components.interfaces.nsIAppShellService)
  64.                                                                 .hiddenDOMWindow;
  65.             if ("ehhNoRequirementsWarning" in hiddenWnd)
  66.                 noWarning.value = true;
  67.             else
  68.                 hiddenWnd.ehhNoRequirementsWarning = true;
  69.         }
  70.  
  71.         if (!noWarning.value) {
  72.             setTimeout(function() {
  73.                 var stringService = Components.classes["@mozilla.org/intl/stringbundle;1"]
  74.                                                                             .getService(Components.interfaces.nsIStringBundleService);
  75.                 var strings = stringService.createBundle("chrome://elemhidehelper/locale/global.properties");
  76.                 var promptService = Components.classes['@mozilla.org/embedcomp/prompt-service;1']
  77.                                                                             .getService(Components.interfaces.nsIPromptService);
  78.                 promptService.alertCheck(window,
  79.                         strings.GetStringFromName("noabp_warning_title"),
  80.                         strings.formatStringFromName("noabp_warning_text", [requiredVersion], 1),
  81.                         strings.GetStringFromName("noabp_warning_disable"),
  82.                         noWarning);
  83.  
  84.                 if (noWarning.value) {
  85.                     try {
  86.                         branch.setBoolPref("ehh.norequirementswarning", true);
  87.                     } catch(e) {}
  88.                 }
  89.             }, 0);
  90.         }
  91.         return;
  92.     }
  93.  
  94.     ehhInit2();
  95. }